<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <th:block th:include="include :: header('工单管理列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <div class="col-sm-12 search-collapse">
            <form id="formId" class="layui-form">
                <div class="layui-form-item">
                    <!--                    <label class="layui-form-label">标题：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="title" placeholder="请输入标题"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">620 数量：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="lowNum" placeholder="请输入620 数量"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">650 数量：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="highNum" placeholder="请输入650 数量"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">其他 数量：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="otherNum" placeholder="请输入其他 数量"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">配送人：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="sender" placeholder="请输入配送人"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">出库人：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="invOutBy" placeholder="请输入出库人"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">接收者：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="accepter" placeholder="请输入接收者"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <label class="layui-form-label">工单号：</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" text="text" name='id' placeholder="请输如工单号">
                    </div>
                    <label class="layui-form-label">工单状态：</label>
                    <div class="layui-input-inline">
                        <select name="status" dict-code="input">
                            <option value="">所有</option>
                            <option value="check">待核验</option>
                            <option value="delete">删除</option>
                            <option value="send">配送中</option>
                            <option value="over">完成</option>
                        </select>
                    </div>

                    <!--                    <label class="layui-form-label">抄送列表id：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="carbonCopyList" placeholder="请输入抄送列表id"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">取货单位id：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="invOutDept" placeholder="请输入取货单位id"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">收货单位id 去向部门id：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="acceptDept" placeholder="请输入收货单位id 去向部门id"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">内容：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="content" placeholder="请输入内容"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">修改人：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="updateName" placeholder="请输入修改人"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">工单发起人名称：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="createName" placeholder="请输入工单发起人名称"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">配送人名称：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="senderName" placeholder="请输入配送人名称"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">出库人名称：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="invOutName" placeholder="请输入出库人名称"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">接收人名称：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="accepterName" placeholder="请输入接收人名称"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">取货部门名称：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="invOutDeptName" placeholder="请输入取货部门名称"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <!--                    <label class="layui-form-label">收货部门名称：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="acceptDeptName" placeholder="请输入收货部门名称"-->
                    <!--                               class="layui-input"/>-->
                    <!--                    </div>-->
                    <label class="layui-form-label">是否失效：</label>
                    <div class="layui-input-inline">
                        <select name="enable">
                            <option value="">所有</option>
                            <option value="1">失效</option>
                            <option value="0">未失效</option>
                        </select>
                    </div>
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="order-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="order-table" lay-filter="order-table"></table>
        <script type="text/html" id="order-toolbar">
            <button sec:authorize="hasPermission('/work/order/add','work:order:add')"
                    class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
                新增
            </button>
            <button sec:authorize="hasPermission('/work/order/remove','work:order:remove')"
                    class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
                <i class="layui-icon layui-icon-delete"></i>
                删除
            </button>
        </script>
        <script type="text/html" id="order-bar">
            <button sec:authorize="hasPermission('/work/order/edit','work:order:edit')"
                    class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i
                    class="layui-icon layui-icon-edit"></i>
            </button>
            <button sec:authorize="hasPermission('/work/order/remove','work:order:remove')"
                    class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i
                    class="layui-icon layui-icon-delete"></i>
            </button>
        </script>
        <!--序号-->
        <script id="index" type="text/html">
            <span>{{d.LAY_TABLE_INDEX + 1}}</span>
        </script>
        <script id="order-status" type="text/html">
            {{#if (d.status === 'delete') { }}
            <span>删除</span>
            {{# }else if(d.status === 'over') { }}
            <span>完成</span>
            {{# }else if(d.status === 'send') { }}
            <span>配送中</span>
            {{# }else if(d.status === 'check') { }}
            <span>待核验</span>
            {{# } }}
        </script>
        <script id="file-image" type="text/html">
            <a href="javascript:void(0);" class="pear-text">查看</a>
        </script>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery', 'dictionary'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;

        let prefix = "/work/order/";

        let cols = [
            [
                {type: 'checkbox'},
                {
                    field: 'index',
                    title: '序号',
                    templet: "#index"
                },
                {
                    field: 'id',
                    title: '工单号'
                },
                // {
                //     field: 'title',
                //     title: '标题'
                // },
                {
                    field: 'lowNum',
                    title: '620 数量'
                },
                {
                    field: 'highNum',
                    title: '650 数量'
                },
                // {
                //     field: 'otherNum',
                //     title: '其他 数量'
                // },
                // {
                //     field: 'sender',
                //     title: '配送人'
                // },
                // {
                //     field: 'invOutBy',
                //     title: '出库人'
                // },
                // {
                //     field: 'accepter',
                //     title: '接收者'
                // },
                // {
                //     field: 'sendTime',
                //     title: '配送时间'
                // },
                // {
                //     field: 'acceptTime',
                //     title: '接收时间（工单结束时间）'
                // },
                {
                    field: 'status',
                    title: '工单状态',
                    templet: '#order-status'
                },
                // {
                //     field: 'carbonCopyList',
                //     title: '抄送列表id'
                // },
                // // {
                // //     field: 'invOutDept',
                // //     title: '取货单位id'
                // // },
                // {
                //     field: 'acceptDept',
                //     title: '收货单位id 去向部门id'
                // },
                // {
                //     field: 'remark',
                //     title: '备注'
                // },
                // {
                //     field: 'content',
                //     title: '内容'
                // },
                {
                    field: 'fileId',
                    title: '图片信息',
                    templet: "#file-image",
                    event: "file-image"
                },
                // {
                //     field: 'updateName',
                //     title: '修改人'
                // },
                {
                    field: 'createName',
                    title: '发起人名称'
                },
                {
                    field: 'senderName',
                    title: '配送人名称'
                },
                // {
                //     field: 'invOutName',
                //     title: '出库人名称'
                // },
                {
                    field: 'accepterName',
                    title: '接收人名称'
                },
                {
                    field: 'invOutDeptName',
                    title: '取货部门名称'
                },
                {
                    field: 'acceptDeptName',
                    title: '收货部门名称'
                },
                {
                    field: 'invOutTime',
                    title: '出库时间'
                },
                {
                    field: 'createTime',
                    title: '工单创建时间'
                },
                {
                    field: 'enable',
                    title: '是否启用'
                },
                {title: '操作', toolbar: '#order-bar', align: 'center', width: 130}
            ]
        ]

        table.render({
            elem: '#order-table',
            url: prefix + 'data',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#order-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports'],
            done: function (res, curr, count) {
                // $(".layui-table-box").find("[data-field='id']").css("display","none")
            }
        });

        table.on('tool(order-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            } else if (obj.event === 'file-image') {
                window.show(obj);
            }
        });

        table.on('toolbar(order-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        form.on('submit(order-query)', function (data) {
            table.reload('order-table', {where: data.field})
            return false;
        });

        window.add = function () {
            layer.open({
                type: 2,
                title: '新增工单管理',
                shade: 0.1,
                area: ['550px', '500px'],
                content: prefix + 'add'
            });
        }

        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改工单管理',
                shade: 0.1,
                area: ['550px', '500px'],
                content: prefix + 'edit?id=' + obj.data['id']
            });
        }

        window.show = function (obj) {
            let content = obj.data.content;
            if (content == undefined || content == "") {
                layer.msg("当前没有图片展示", {icon: 2, time: 1000})
                return
            }
            if (content != null && content != '') {
                let id = JSON.parse(JSON.parse(obj.data.content).out).ids;
                let imgArr = [];
                for (let i = 0; i < id.length; i++) {
                    let fileId = id[i]; //图片id
                    let image = "/system/file/download/" + fileId;
                    let img = {};
                    img.src = image;
                    imgArr.push(img);
                }
                layer.photos({
                    photos: {
                        "title": "预览图片",
                        "start": 0,
                        "data": imgArr
                    }
                    , anim: 5
                });
            }
        }

        window.remove = function (obj) {
            layer.confirm('确定要删除该工单管理', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: prefix + "remove/" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.batchRemove = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些工单管理', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: prefix + "batchRemove",
                    dataType: 'json',
                    data: {"ids": ids},
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('order-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.refresh = function (param) {
            table.reload('order-table', {where: param});
        }
    })
</script>
</body>
</html>